import { ApiProperty } from '@nestjs/swagger';
import { User } from './user.entity';
import { ETransactionType } from '../../enum/transaction.enum';
import {
	Column,
	CreateDateColumn,
	UpdateDateColumn,
	Entity,
	ManyToOne,
	PrimaryGeneratedColumn,
} from 'typeorm';

@Entity()
export class Transaction {
	constructor(props?: Partial<Transaction>) {
		Object.assign(this, props);
	}

	@PrimaryGeneratedColumn()
	public id!: string;

	@ManyToOne(() => User, (user) => user.telegramId)
	public user!: User;
	@Column()
	userTelegramId!: string;

	@ApiProperty({ example: 'Refill', description: 'type transaction' })
	@Column({
		type: 'enum',
		enum: ETransactionType,
	})
	public typeTransaction!: ETransactionType;

	@ApiProperty({ example: '300', description: 'transaction amount' })
	@Column({
		type: 'numeric',
	})
	public amount!: number;

	@ApiProperty({ example: true, description: 'result operation' })
	@Column({
		type: 'boolean',
		default: false,
	})
	public result!: boolean;

	@ApiProperty({ example: 'smirnova', description: 'login' })
	@CreateDateColumn({ nullable: true, name: 'created_at' })
	createdAt!: Date;

	@ApiProperty({ example: 'smirnova', description: 'login' })
	@UpdateDateColumn({ nullable: true, name: 'updated_at' })
	updatedAt!: Date;
}
